package huixue.cn.com.rxapp.helper;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;

import huixue.cn.com.rxapp.util.LogUtils;

/**
 * Created by gongdongyang 2019/7/17
 * Describe:
 */
public class ImageViewHelper {

    public static Bitmap handleImageViewHue(Bitmap bitmap,float liangdu,float baohedu,float duibidu){

        LogUtils.d("==handleImageViewHue==liangdu="+liangdu+"=baohedu="+baohedu+"=duibidu="+duibidu);

        Bitmap bmp = Bitmap.createBitmap(bitmap.getWidth(),bitmap.getHeight(), Bitmap.Config.ARGB_8888);

        Canvas canvas = new Canvas(bmp);

        ColorMatrix liangduColorMatrix = new ColorMatrix();
        liangduColorMatrix.setScale(liangdu,liangdu,liangdu,1);

        ColorMatrix baoheduColorMatrix = new ColorMatrix();
        baoheduColorMatrix.setSaturation(baohedu);

        ColorMatrix duibiduColorMatrix = new ColorMatrix();
        duibiduColorMatrix.setRotate(0,duibidu);
        duibiduColorMatrix.setRotate(1,duibidu);
        duibiduColorMatrix.setRotate(2,duibidu);

        ColorMatrix imageColrMatrix = new ColorMatrix();
        imageColrMatrix.postConcat(duibiduColorMatrix);
        imageColrMatrix.postConcat(baoheduColorMatrix);
        imageColrMatrix.postConcat(liangduColorMatrix);

        Paint paint = new Paint();
        paint.setAntiAlias(true);
        //paint.setDither(true);
        paint.setColorFilter(new ColorMatrixColorFilter(imageColrMatrix));

        canvas.drawBitmap(bitmap,0,0,paint);

        return bmp;

    }
}
